package huawei

import (
	"gitee.com/amoyx/cloud-provider/pkg/cloud/huawei/compute"
	"gitee.com/amoyx/cloud-provider/pkg/cloud/huawei/logservice"
	"gitee.com/amoyx/cloud-provider/pkg/cloud/huawei/network"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
)

// HCSCloudInterface 华为云接口
type HCSCloudInterface interface {
	Computes() compute.CloudComputeInterface
	Networks() network.CloudNetworkInterface
	LogServices() logservice.CloudLogServiceInterface
}

type HCSCloudClient struct {
	secretId    string
	secretKey   string
	credentials *basic.Credentials
}

func NewHCSCloudClient(ak string, sk string) HCSCloudInterface {
	auth := basic.NewCredentialsBuilder().
		WithAk(ak).
		WithSk(sk).
		Build()
	return &HCSCloudClient{
		credentials: auth,
		secretId:    ak,
		secretKey:   sk,
	}
}

func (h *HCSCloudClient) Computes() compute.CloudComputeInterface {
	return compute.NewCompute(h.Credentials())
}

func (h *HCSCloudClient) Networks() network.CloudNetworkInterface {
	return network.NewNetwork(h.Credentials())
}

func (h *HCSCloudClient) LogServices() logservice.CloudLogServiceInterface {
	return logservice.NewLogService(h.Credentials())
}

func (h *HCSCloudClient) SecretId() string {
	return h.secretId
}

func (h *HCSCloudClient) SecretKey() string {
	return h.secretKey
}

func (h *HCSCloudClient) Credentials() *basic.Credentials {
	return h.credentials
}
